import axios from 'axios'
import { Toast,Notify } from 'vant';
//创建axios实例
var service = axios.create({
    timeout: 5000,
    headers: {
        'content-type': 'application/json',
        "token":''
    }
})
export default {

    //get请求，其他类型请求复制粘贴，修改method
    get(url, param) {
        Toast.loading({
            message: '加载中...',
            forbidClick: true,
            duration: 0,
        });

        return new Promise((cback, reject) => {
            service({
                method: 'get',
                url,
                params: param,
            }).then(res => {

                Toast.clear();
                cback(res);
            }).catch(err => {
                Toast.clear();
                Notify({ type: 'danger', message: '请重试' });
            })

        })
    },
    post(url, param) {
        Toast.loading({
            message: '加载中...',
            forbidClick: true,
            duration: 0,
        });

        return new Promise((cback, reject) => {
            service({
                method: 'post',
                url,
                data: param,
            }).then(res => {

                Toast.clear();
                cback(res);
            }).catch(err => {
                Toast.clear();
                Notify({ type: 'danger', message: '请重试' });
            })

        })
    }
}
